import { TokenType } from '../src/token.js';
import { Lexer } from '../src/lexer.js';

function testNextToken() {
    const input = `'=+(){},;'`
    const tests = [
        {expectedType: TokenType.ASSIGN, expectedLiteral: '='},
        {expectedType: TokenType.PLUS, expectedLiteral: '+'},
        {expectedType: TokenType.LPAREN, expectedLiteral: '('},
        {expectedType: TokenType.RPAREN, expectedLiteral: ')'},
        {expectedType: TokenType.LBRACE, expectedLiteral: '{'},
        {expectedType: TokenType.RBRACE, expectedLiteral: '}'},
        {expectedType: TokenType.COMMA, expectedLiteral: ','},
        {expectedType: TokenType.SEMICOLON, expectedLiteral: ';'},
        {expectedType: TokenType.EOF, expectedLiteral: ''},
    ]
    const l = new Lexer(input);
    for (let i = 0; i < tests.length; i++) {
        const tt = tests[i];
        const tok = l.nextToken();
        if (tok.type !== tt.expectedType) {
            console.error(
                `test[${i}] - tokenType wrong . excepted=${tt.expectedType}, got=${tok.type}`
            )
        }
        if (tok.literal !== tt.expectedLiteral) {
            console.error(
                `test[${i}] - tokenType wrong . excepted=${tt.expectedLiteral}, got=${tok.literal}`
            )
        }
    }
    console.log('ok')
}
testNextToken();